	Load()
	ajax(api.order.list,{
		where_json:JSON.stringify({
			order_id:['in','{$Think.get.order_id}']
		})
	},'post').done(function(res){
		
		for(let key in res.data[0]){
			
			if((typeof res.data[0][key])=='object'&&!Array.isArray(res.data[0][key])){
				for(var key1 in res.data[0][key]){
					res.data[0][key1]=res.data[0][key][key1]
				}
			}
		}
		console.log(res)
		Load(1)
		if(res.code==1){
			for(var key in res.data[0]){
				if(key=='pre_time'){
					var pre_time=parseInt(res.data[0][key]/60)+'分钟';
					$('.'+key).val(pre_time)
				}else{
					$('.'+key).html(res.data[0][key])
					$('.'+key).val(res.data[0][key])
				}
				
			}
		}else{
//			Err(res.msg)
			Err('数据请求失败')
		}
	}).fail(function(){
		
	})
	$('.driver_name').on('click',function(){
		opsearch("{:url('html/plus/driver')}?op=search")
	});
	$('.chedui').on('click',function(){
		opsearch("{:url('html/car/chedui')}?op=search")
	});
	$('.number').on('click',function(){
		opsearch("{:url('html/car/car')}?op=search")
	});
	
	$('.dispatch').on('click',function(){
	
		if($('.driver_id').val()){
			if($('.car_id').val()){
				Load()
				ajax(api.order.dispatch,{
					order_id:"{$Think.get.order_id}",
					driver_id:$('.driver_id').val(),
					car_id:$('.car_id').val(),
					car_number:$('.number').val()
				},'post').done((res)=>{
					Load(1)
					if(res.code==1){
						Msg('派车成功');
						window.location.href=path.order.index+'?state=5'
					}else{
						Err(res.msg)
					}
				}).fail(()=>{
					Load(1)
					Err('请求失败')
				})
				
			}else{
				Err('请选择车辆')
			}
		}else{
			Err('请选择司机')
		}
		
		
	})
	function paidan(){
		 var fi=1;
		var page=1;
		var main=[[ //表头
		{field: 'name', title: '司机',  sort: true, fixed: 'left',minWidth:100, templet: '#carId'}
        ,{field: 'phone', title: '司机电话',  sort: true}
        ,{field: 'end_time', title: '上次订单结算时间'} 
        ,{field: 'task_time',width:300, title: '预约时间'}
        ,{field: 'number', width:200,title: '绑定车辆', sort: true}
        ,{field:'work_state2', title:'状态'}
       ,{ title: '查看司机排单情况',minWidth:170, toolbar:'#operation',fixed: 'right'}
     ]];
		var data={};
	    data.page=page;
	    data.pagenum=10;
	    var where_json={};
	   
		var paidan=layer.open({
		  type: 1,
		  offset: 'auto',
		  title:'司机排单',
		  shade: 0,
		  skin: 'layui-layer-rim', //加上边框
		  area: ['60%', '70%'], //宽高
		  content: `<div style='padding:10px;font-size:14px'>
		  <form class='layui-form'>
		  	<div class="layui-form-item">
		  		<div class="layui-input-inline">
		  			<input class='driver_name layui-input'  placeholder="请输入司机姓名"/>
		  		</div>
		  		<div class="layui-input-inline">
		  			<input class='phone layui-input'  placeholder="请输入手机号"/>
		  		</div>
		  		<div class="layui-input-inline">
		  			<input class='number layui-input'  placeholder="请输入车牌号"/>
		  		</div>
		  		<div class="layui-input-inline">
		  			<select name="work_state" class='work_state'>
						<option value="1">执行任务中</option>
						<option value="2">有预约订单</option>
						<option selected value="3">听单中</option>
						<option value="4">下班</option>
					</select>
		  		</div>
		  		<div class="layui-input-inline">
		  		<button type="button" class="layui-btn  layui-btn-secondary am-radius search">查询</button>
		  		</div>
		  	</div>
		  	 </form>
		  	<div class="am-u-sm-12 cl-p" style='font-size:12px'>
				<span>听单中司机数量:<i style='color:#5FB878;font-weight: 900;' class='driver1'></i>人|</span>
				<span>执行任务司机数量:<i style='color:#FF5722;font-weight: 900;' class='driver2'></i>人|</span>
				<span>有预约单司机数量:<i style='color:#FFB800;font-weight: 900;' class='driver3'></i>人|</span>
				<span>下班司机数量:<i style='color:#1E9FFF;font-weight: 900;' class='driver4'></i>人</span>
			</div>	
		  	<table  class="layui-hide" id='driver' lay-filter="driver"></table>
		  	<div class="am-u-lg-12 am-cf" style='color:#888'>
				
				<div class="am-fr">
					<ul class="pagination">
						
					</ul>
				</div>
			</div>
			<div class="am-u-lg-12 am-cf">
					
				
			</div>
		  </div>`,
		  success:function(){
		  	form.render();
			table.render({
				elem: '#driver',
				cellMinWidth: 80,
				cols: main,
				data: [],
				limit: 10,
				even: true
			});
			if(fi == 1) {
				laypage.render({
					elem: 'page',
					count: 0,
					layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
					theme: '#1E9FFF',
					jump: function(obj, first) {
						if(!first) {
							page = obj.curr
							data.page = page
							pagenum = obj.limit
							data.pagenum = pagenum
							ajaxcar(data)
						} else {
			
						}
					}
				});
				fi = 2
    		}
//		  	$('.work_state').selected({
//		  		 btnWidth: '100%',
//			    btnSize: 'sm',
//			    maxHeight: '200px'
//		  	});
//		  	ajaxdriver(data)
		  	function ajaxdriver(data){
					Load()
				$.ajax({
					type: "post",
					url: api.driver.list,
					data: data,
					success: function(res) {
						console.log(res);
						Load(1)
						$("#loading-first").fadeOut(500);
						res=driverstate(res)
						$('.driver1').html(res.work.driver1)
						$('.driver2').html(res.work.driver2)
						$('.driver3').html(res.work.driver3)
						$('.driver4').html(res.work.driver4)
						for(var tidx=0;tidx<res.data.length;tidx++){
							res.data[tidx].end_time=timestampToTime(res.data[tidx].end_time)
						}
						$('.driver_paidan tbody').html(tbodymainf2(res.data, 1, tddata, addoperation, 'driver_id'))
						$('.pagination').html(pagechang1(res.count, 10, page))
						$('.laquo').on('click', function() {
							page-=1
							data.page=page
							ajaxdriver(data)
						})
						$('.pageli').on('click', function() {
							page=$(this).html()
							data.page=page
							ajaxdriver(data)
						})
						$('.raquo').on('click', function() {
							page+=1
							data.page=page
							ajaxdriver(data)
						})
						$('.search').unbind()
						$('.search').on('click',function(){
							console.log($('.work_state').val())
							var states=''
							for(var sidx=0;sidx<$('.work_state').val().length;sidx++){
								if(sidx==0){
									states+=$('.work_state').val()[sidx]
								}else{
									states+=(","+$('.work_state').val()[sidx])
								}
							}
							console.log(states)
							data.name=$('.driver_name').val();
							data.number=$('.number').val();
							data.phone=$('.phone').val();
							data.state=states;
							ajaxdriver(data);
						})
						$('.choose').on('click',function(){
							console.log($(this).closest('tr').data('id'))
							var obj=getdetail($(this).closest('tr').data('id'),res.data,'driver_id')
							console.log(obj)
							$('.driver').val(obj.name)
							$('.driver_id').val(obj.driver_id)
							$('.car_number').val(obj.number)
							$('.CarId').val(obj.car_id)
							layer.close(paidan)
						})
						$('.look').on('click',function(){
							window.open("{:url('admin/driver/scheduling')}?driver_id="+$(this).closest('tr').data('id'));
						})
					},
					error:function(){
						Load(1)
						Err('请求失败')
					}
				});
				}
		  }
		});
	}
